export class MjWeaveItem {



    public static Weave_Type = {
        Null: 0, //
        Peng: 1, //碰
        Gang: 2, //杠
        AnGang: 3, //暗杠
        // Bian: 4, //边
        // Za: 5, //砸
        // GangZa: 6, //杠砸
        // AnGangZa: 7, //暗杠砸
        // Zuan: 8, //钻
    }

    public weaveType: number; //组合类型     
    public operateChair: number = 0 //操作用户
    public provideChair: number; //供应用户
    public provideCard: number; //供应牌
    public isScoreGang: boolean = true
    public cardList: Array<number> = []

    constructor(weaveType: number = 0, operateChair: number = 0, provideChair: number = 0, provideCard: number = 0, cardList: Array<number> = []) {
        this.weaveType = weaveType;
        this.operateChair = operateChair;
        this.provideChair = provideChair;
        this.provideCard = provideCard;
        this.cardList = cardList;
    }

    public static pushMjWeaveItem(mjWeaveItem: MjWeaveItem, mjWeaveList: Array<MjWeaveItem>) {
        let isFind: boolean = false;
        if (mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.AnGang
            || mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.Gang) {
            for (let i = 0; i < mjWeaveList.length; i++) {
                let tempMjWeave: MjWeaveItem = mjWeaveList[i]
                if (tempMjWeave.weaveType == MjWeaveItem.Weave_Type.Peng) {
                    if (tempMjWeave.provideCard == mjWeaveItem.provideCard) {
                        isFind = true;

                        //新家的，补杠，补杠砸
                        if (mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.AnGang) {
                            mjWeaveItem.weaveType = MjWeaveItem.Weave_Type.Gang
                        }
                        mjWeaveList[i] = mjWeaveItem;
                        break
                    }
                }
            }
        }
        if (!isFind) {
            mjWeaveList.push(mjWeaveItem)
        }
    }

    public static deleteHandCardByWeaveItem(mjWeaveItem: MjWeaveItem, handCardList: Array<number>) {
        let deleteCardList: Array<number> = mjWeaveItem.cardList.concat()
        if (mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.Gang || mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.AnGang
        ) {
            deleteCardList.push(mjWeaveItem.cardList[0])
        }
        else if (mjWeaveItem.weaveType == MjWeaveItem.Weave_Type.Peng) {
            // deleteCardList = deleteCardList.splice(0, 2)
        }
        for (let i = 0; i < deleteCardList.length; i++) {
            for (let j = handCardList.length - 1; j >= 0; j--) {
                if (handCardList[j] == deleteCardList[i]) {
                    handCardList.splice(j, 1)
                    break;
                }
            }
        }
    }


    public clone() {
        let mjWeaveItem: MjWeaveItem = new MjWeaveItem()
        mjWeaveItem.weaveType = this.weaveType
        mjWeaveItem.operateChair = this.operateChair
        mjWeaveItem.provideChair = this.provideChair
        mjWeaveItem.provideCard = this.provideCard
        mjWeaveItem.cardList = this.cardList.concat()
        return mjWeaveItem
    }

}